package cn.psvmc.cxzapi.controller.ticket;

import cn.psvmc.cxzapi.model.common.DetailEntity;
import cn.psvmc.cxzapi.model.ticket.TTicketReplies;
import cn.psvmc.cxzapi.response.Result;
import cn.psvmc.cxzapi.response.ResultGenerator;
import cn.psvmc.cxzapi.service.ticket.TTicketRepliesService;
import cn.psvmc.cxzapi.util.ToolUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 工单处理
 * @Author auto
 * @Date 2024-08-12
 */
@RestController
@RequestMapping("/ticket_replies")
public class TTicketRepliesController {

    @Resource
    private TTicketRepliesService tTicketRepliesService;

    /**
    * @Author auto 2024-08-12 新增工单处理表
    * @Param tTicketReplies 工单处理表
    * @Return cn.psvmc.cxzapi.response.Result
    */
    @PostMapping("/add")
    public Result add(@RequestBody TTicketReplies tTicketReplies) {
        ToolUtils.validation(new Object[]{
                tTicketReplies.getTicketId(), "工单id", 1
                , tTicketReplies.getReplier(), "回复人", 2
                , tTicketReplies.getComm(), "回复内容", 2
        });

        int addResult = tTicketRepliesService.add(tTicketReplies);
        if (addResult > 0) {
            return ResultGenerator.genSuccessResult("保存成功！");
        }
        return ResultGenerator.genFailResult("保存失败！");
    }

    /**
    * @Author auto 2024-08-12 查询工单处理表详情
    * @Param [entity]
    * @Return cn.psvmc.cxzapi.response.Result
    */
    @PostMapping("/detail")
    public Result detail(@RequestBody DetailEntity entity) {
        Integer id = entity.getId();
        ToolUtils.validation(new Object[]{id, "id", 1});
        return ResultGenerator.genSuccessResult("查询成功", tTicketRepliesService.detail(id));
    }
}
